$(document).ready(function(){
	$("#up_text").click(function(){
		now_id = now_id - 1;
		if(now_id<0) now_id = 0;
		checklink(now_id);
		$(this).blur();
		return false;
	});
	$("#down_text").click(function(){
		now_id = now_id + 1;
		if(now_id>imgJson.length-1) now_id = imgJson.length-1;
		checklink(now_id);
		$(this).blur();
		return false;
	});
	$("#up_img").click(function(){
		now_id = now_id - 1;
		if(now_id<0) now_id = 0;
		checklink(now_id);
		$(this).blur();
		return false;
	});
	$("#down_img").click(function(){
		now_id = now_id + 1;
		if(now_id>imgJson.length-1) now_id = imgJson.length-1;
		checklink(now_id);
		$(this).blur();
		return false;
	});
	$("a[id^='spic']").click(function(){
		now_id = $(this).attr("id").replace(/spic/,'');
		checklink(now_id);
		$(this).blur();
		return false;
	});
});

function checklink(id){
	var up_text = $("#up_text");
	var down_text = $("#down_text");
	var up_img = $("#up_img");
	var down_img = $("#down_img");
	if(id==0){
		if(imgJson.length==1){
			up_text.removeAttr("href");
			up_text.addClass("ends");
			down_text.removeAttr("href");
			down_text.addClass("ends");
			up_img.removeAttr("href");
			up_img.children().attr("src","images/but_larger_up2.gif");
			up_img.children().attr("alt","");
			down_img.removeAttr("href");
			down_img.children().attr("src","images/but_larger_down2.gif");
			down_img.children().attr("alt","");
		}else{
			up_text.removeAttr("href");
			up_text.addClass("ends");
			if(down_text.attr("href")==undefined || down_text.attr("href")==""){
				down_text.attr("href","#");
				down_text.removeAttr("class");
			}
			up_img.removeAttr("href");
			up_img.children().attr("src","images/but_larger_up2.gif");
			up_img.children().attr("alt","");
			if(down_img.attr("href")==undefined || down_img.attr("href")==""){
				down_img.children().attr("src","images/but_larger_down.gif");
				down_img.children().attr("alt","下一张");
				down_img.attr("href","#");
			}
		}
	}else if(id==imgJson.length-1){
		down_text.removeAttr("href");
		down_text.addClass("ends");
		if(up_text.attr("href")==undefined || up_text.attr("href")=="") {
			up_text.attr("href","#");
			up_text.removeClass("ends");
		}
		down_img.removeAttr("href");
		down_img.children().attr("src","images/but_larger_down2.gif");
		down_img.children().attr("alt","");
		up_img.children().attr("src","images/but_larger_up.gif");
		up_img.children().attr("alt","上一张");
		up_img.attr("href","#");
	}else{
		if(down_text.attr("href")==undefined || down_text.attr("href")==""){
			down_text.attr("href","#");
			down_text.removeAttr("class");
		}
		if(up_text.attr("href")==undefined || up_text.attr("href")==""){
			up_text.attr("href","#");
			up_text.removeClass("ends");
		}
		if(down_img.attr("href")==undefined || down_img.attr("href")==""){
			down_img.children().attr("src","images/but_larger_down.gif");
			down_img.children().attr("alt","下一张");
			down_img.attr("href","#");
		}
		if(up_img.attr("href")==undefined || up_img.attr("href")==""){
			up_img.children().attr("src","images/but_larger_up.gif");
			up_img.children().attr("alt","上一张");
			up_img.attr("href","#");
		}
	}
	$("a[id^='spic']").each(function(){
		if($(this).attr("href")==undefined || $(this).attr("href")==""){
			$(this).attr("href","#");
			$(this).removeAttr("class");
		}
	});
	$("#spic"+id).addClass("choice");
	$("#spic"+id).removeAttr("href");
	$("#bigPic").attr("src",imgJson[id]);
}